package com.demo.bio.four;

import java.net.ServerSocket;
import java.net.Socket;

/**
 * 目标：开发伪异步通信架构
 * @author wangning
 * @create 2022-01-05 20:52
 */
public class Server4 {
	public static void main(String[] args) {
		try {
			//1.注册端口
			ServerSocket ss = new ServerSocket(9999);
			//2.定义一个循环接收客户端的socket连接请求
			//初始化一个线程池对象
			HandlerSocketServerPool pool = new HandlerSocketServerPool(3, 10);
			while (true) {
				Socket socket = ss.accept();
				//3.把socket交给线程池进行处理
				//把socket封装成一个任务对象交给线程池处理
				Runnable target = new ServerRunnableTarget(socket);
				pool.execute(target);

			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
